package com.itheima.reggie.common;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@ResponseBody
@ControllerAdvice(annotations = {RestController.class, Controller.class})
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public R<String> exceptionHandler(Exception ex) {
        log.info("异常信息：{}", ex.getMessage());
        return R.error("未知异常");
    }

    @ExceptionHandler(CustomException.class)
    public R<String> customerExceptionHandler(Exception ex) {
        log.info("异常信息：{}", ex.getMessage());
        return R.error(ex.getMessage());
    }
}
